﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OreSystem.Entities;
using OreSystem.DAL;
namespace OreSystem.BLL {
    public class ItemTableBLL {        
        private CarDAL carDAL = new CarDAL();
        private ItemDAL itemDAL = new ItemDAL();
        private LevelDAL levelDAL = new LevelDAL();
        public IList<ItemTable> GetList(DateTime startDate, DateTime endDate) {

            IList<ItemTable> ItemTables = new List<ItemTable>();
            IList<Item> items = itemDAL.GetList();
            foreach (var item in items) {
                Car car = carDAL.GetCarById(item.CarID);
                Level SecondLevel = levelDAL.GetLevelById(car.PID);
                Level FirstLevel = levelDAL.GetLevelById(SecondLevel.PID);
                string caltypeName = string.Empty;
                string worktypeName = string.Empty;
                if (item.CalType == 0)
                {
                    caltypeName = "拉渣";
                }
                else
                {
                    caltypeName = "拉土";
                }
                if (item.WorkType == 0)
                {
                    worktypeName = "白班";
                }
                else
                {
                    worktypeName = "夜班";
                }
                ItemTables.Add(new ItemTable {
                    ID = item.ID,
                    CarID = item.CarID,
                    CarNo = item.CarNumber,
                    times = item.times,
                    Type = item.Type,
                    CreateTime = item.CreateDate,
                    Cubic = car.Cubic,
                    FirstLevelID = FirstLevel.ID,
                    FirstLevelName = FirstLevel.Name,
                    secondLevelName = SecondLevel.Name,
                    SecondLevelID = SecondLevel.ID,
                    Lenght = item.Lenght,
                    CalType = item.CalType,
                    CalTypeName = caltypeName,
                    WorkType = item.WorkType,
                    WorkTypeName = worktypeName
                });
            }
            return ((List<ItemTable>)ItemTables).FindAll(p=>(p.CreateTime >= startDate && p.CreateTime <= endDate));

        }
        public IList<ItemTable> GetList(DateTime startDate, DateTime endDate, int carId)
        {
            var lists = GetList(startDate, endDate);
            return lists.ToList().FindAll(i => i.CarID == carId);
        }
        public IList<Car> GetAllCar()
        {
            return carDAL.GetAll();
        }
    }
}
